package com.hyy.trigger.machine;

import com.hyy.trigger.util.TriggerUtil;
import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters;
import org.squirrelframework.foundation.fsm.impl.AbstractUntypedStateMachine;

import java.util.List;

import static com.hyy.trigger.machine.State.CLEAR;
import static com.hyy.trigger.machine.State.END;

@StateMachineParameters(stateType = String.class, eventType = String.class, contextType = Basket.class)
public class RuleMachine extends AbstractUntypedStateMachine {

    protected void onEntry(String from, String to, String event, Basket basket) {
        if(basket.isEnd()){
            this.fire(TriggerUtil.event(to,END),basket);
        }else {
            List<String> lines = basket.getLines();
            int index = lines.indexOf(to);
            String next = lines.get(index + 1);
            this.fire(TriggerUtil.event(to,next),basket);
        }

    }

}
